package com.elitel.frame.main.entity.vo;

import java.io.Serializable;
import java.util.List;

import lombok.Data;

/**
 * @Description 用于返回分页显示bootstrap Table数据 
 * @author gyf
 * @version v1.0 
 */
@Data
public class PageResponseVo<T> implements Serializable {
	private static final long serialVersionUID = 768549219446295665L;
	private Integer total;//总条数
	// here is provider current row file
	private Integer firstRowPosition;
	private List<T> rows;//当前页数据

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public List<T> getRows() {
		return rows;
	}

	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	public void computeFirstRowPosition(String pageNO, String pageSize){
		Integer currentPage = null, displayNumberOfPage = null;

		try{
			currentPage = Integer.parseInt(pageNO);
			displayNumberOfPage = Integer.parseInt(pageSize);
		}catch (Exception e){
//			System.out.println("computeFirstRowPosition parse fail pageNO = "+ pageNO +  "pageSize ="+ pageSize);
			currentPage = 1;
			displayNumberOfPage = 10;
		}

		computeFirstRowPosition(currentPage, displayNumberOfPage);
	}

	public void computeFirstRowPosition(Integer currentPage, Integer displayNumberOfPage){
		if(rows == null || rows.size() < 1){
			firstRowPosition = 0;
			return;
		}

		if(currentPage < 1 || displayNumberOfPage < 1){
			firstRowPosition = 0;
			return;
		}

		firstRowPosition = (currentPage - 1) * displayNumberOfPage  + 1;
	}
}
